package cn.itcast.com.network.tcp.exer03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //创建一个socket对象,此时已经发起连接了
        //参数是目的服务器的ip和端口
        //而socket的ip和端口默认是本机ip，此时连接已经建立
        Socket socket = new Socket("127.0.0.1",8282);

        //从建立好连接的socket对象中，获取需要的流
        //可以接受可以发送
        //读取键盘
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = socket.getOutputStream();
        String s;
        //循环读取
        while ((s = br.readLine())!=null){
            outputStream.write(s.getBytes());
            outputStream.write("\n".getBytes());
        }
        socket.close();
    }
}
